package com.yangyongfeng.android_ndk;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.yangyongfeng.JNI_library.InstanceFieldAccess;
import com.yangyongfeng.JNI_library.InstanceMethodAccess;
import com.yangyongfeng.JNI_library.MyMath;
import com.yangyongfeng.JNI_library.StaticFieldAccess;
import com.yangyongfeng.JNI_library.StaticMethodAccess;

public class MainActivity extends AppCompatActivity {
    private  final  String TAG =  "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MyMathTest();
        InstanceFieldAccessTest();
        StaticFieldAccessTest();
        instanceMethodAccessTest();
        staticMethodAccessTest();
    }

    private void  InstanceFieldAccessTest(){
        InstanceFieldAccess fieldAccess = new InstanceFieldAccess("Access filed",'O');
        Log.d(TAG,fieldAccess.getS() + fieldAccess.getType());
        fieldAccess.accessField();
        Log.d(TAG,"In Java:" + "c.s = \"" + fieldAccess.getS() +  "\""  + fieldAccess.getType() +  "\"");
    }

    private  void MyMathTest() {
        Log.d( "MainActivity", Integer.toString(MyMath.sum(1,2)));
    }

    private void StaticFieldAccessTest(){
        Log.d(TAG,this.toString());
        StaticFieldAccess fieldAccess = new StaticFieldAccess();
        Log.d(TAG,Integer.toString(StaticFieldAccess.my_sex));
        Log.d(TAG,"FieldAccess addr:" + fieldAccess.toString());
        fieldAccess.accessStaticField();
        //StaticFieldAccess.accessStaticField();
        Log.d(TAG,"New value: " + StaticFieldAccess.my_sex);
    }

    private void instanceMethodAccessTest(){
        Log.d(TAG,"Instance method access test start.");
        InstanceMethodAccess instanceMethodAccess =  new InstanceMethodAccess();
        instanceMethodAccess.nativeMethod();

    }

    private  void staticMethodAccessTest(){
        Log.d(TAG,"Static method access test start.");
        StaticMethodAccess staticMethodAccess =  new StaticMethodAccess();
        staticMethodAccess.methodAccess(0);
        Log.d(TAG,"Static method access test end.");
    }
}
